package com.example.pfe_copie_finale;
import java.util.Calendar;

import com.example.pfe_copie_finale.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

import android.os.Bundle;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Toast;

public class Devis extends Activity implements
		AdapterView.OnItemSelectedListener {
	
	private EditText pickDate;
	private EditText pickDate1;
	private int mYear;
	private int mMonth;
	private int mDay;
	private int mYear1;
	private int mMonth1;
	private int mDay1;
	static final int DATE_DIALOG_ID1 = 1;
	static final int DATE_DIALOG_ID2 = 2;
	TextView selection;
	String[] items = { "thisjjj", "is", "a", "really", 
			"really2", "really3",
			"really4", "really5", "silly", "list" };

	@Override
	

	

	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bon_commande);
	
		
		pickDate = (EditText) findViewById(R.id.datep);
		pickDate1 = (EditText) findViewById(R.id.datel);
		selection = (TextView) findViewById(R.id.selection);
		

		Spinner spin = (Spinner) findViewById(R.id.spinner);
		spin.setOnItemSelectedListener(this);

		ArrayAdapter aa = new ArrayAdapter(
				this,
				android.R.layout.simple_spinner_item, 
				items);

		aa.setDropDownViewResource(

				android.R.layout.simple_spinner_dropdown_item);
		spin.setAdapter(aa);
		
		
		
		
		
		pickDate.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
			showDialog(DATE_DIALOG_ID1);
			}
			});
			final Calendar c = Calendar.getInstance();
			mYear = c.get(Calendar.YEAR);
			mMonth = c.get(Calendar.MONTH);
			mDay = c.get(Calendar.DAY_OF_MONTH);
			updateDisplay(DATE_DIALOG_ID1);
			
		
		
		pickDate1.setOnClickListener(new View.OnClickListener() {

		public void onClick(View v) {
		showDialog(DATE_DIALOG_ID2);
		}
		});
		final Calendar c1 = Calendar.getInstance();
		mYear1 = c1.get(Calendar.YEAR);
		mMonth1 = c1.get(Calendar.MONTH);

		mDay1 = c1.get(Calendar.DAY_OF_MONTH);
		updateDisplay(DATE_DIALOG_ID2);
		
		
		
	
	}
	
	
	public void onItemSelected(AdapterView<?> parent, View v, int position,
			long id) {
	}

	public void onNothingSelected(AdapterView<?> parent) {}
	protected Dialog onCreateDialog(int id) {
		switch (id) {

		case DATE_DIALOG_ID1:
		    return new DatePickerDialog(this,mDateSetListener,mYear, mMonth, mDay);
		case DATE_DIALOG_ID2:
			return new DatePickerDialog(this,mDateSetListener1,mYear1, mMonth1, mDay1);
		}
		return null;
		}
		protected void onPrepareDialog(int id, Dialog dialog) {
		switch (id) {
		case DATE_DIALOG_ID1 :
		((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);break;

		case DATE_DIALOG_ID2:
			((DatePickerDialog) dialog).updateDate(mYear1, mMonth1, mDay1);break;

		}
		} 
		private void updateDisplay(int id) {
			switch (id) {
			case DATE_DIALOG_ID1 :
				pickDate.setText(
						new StringBuilder()
						// Month is 0 based so add 1
						.append(mDay ).append("-")
						.append(mMonth+1).append("-")
						.append(mYear).append(" "));
			case DATE_DIALOG_ID2:
				pickDate1.setText(
						new StringBuilder()
						 // Month is 0 based so add 1
						.append(mDay1 ).append("-")
						.append(mMonth1+1).append("-")
						.append(mYear1).append(" "));
			}
		
		
		}
		
		private DatePickerDialog.OnDateSetListener mDateSetListener =new DatePickerDialog.OnDateSetListener() {

		public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
		mYear = year;
		mMonth = monthOfYear;
		mDay = dayOfMonth;
		updateDisplay(1);
		}


		};
		private DatePickerDialog.OnDateSetListener mDateSetListener1 =new DatePickerDialog.OnDateSetListener() {

			public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
			mYear1 = year;
			mMonth1 = monthOfYear;
			mDay1 = dayOfMonth;
			updateDisplay(2);
			}


			};
		
			}